﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyRead.API.Appicant.Command.Approval;
using MediatR;

namespace B.S.DataBase.MyRead.API.Appicant.CommandHandler.Approval
{
    public class BackfillingApprovalCommandHandler : IRequestHandler<BackfillingApprovalCommand, APIResult<object>>
    {
        private readonly IBaseRepository<LeaveApplication> leaveappRep;

        public BackfillingApprovalCommandHandler(IBaseRepository<LeaveApplication> leaveappRep)
        {
            this.leaveappRep = leaveappRep;
        }

        public async Task<APIResult<object>> Handle(BackfillingApprovalCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();

            var entity = leaveappRep.GetAll().Result.FirstOrDefault(x => x.LeaveId == request.LeaveId);
            result.Code = APIEnum.查询成功;
            result.Msg = APIEnum.查询成功.ToString();
            result.data= entity;
            return await Task.FromResult(result);
        }
    }
}
